import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'
// import Home from '../components/Home.vue'
// import Welcome from '../components/Welcome.vue'
// import User from '../components/User/User.vue'
// import Roles from '../components/Right/Roles.vue'
// import Rights from '../components/Right/Rights.vue'
// import Goods from '../components/Goods/Goods.vue'
// import Params from '../components/Goods/Params.vue'
// import Categories from '../components/Goods/Categories.vue'
// import AddGoods from '../components/Goods/AddGoods.vue'
// import Order from '../components/Order/Order.vue'
// import Report from '../components/Report/Report.vue'

const Login = () => import('../components/Login.vue')
const Home = () => import('../components/Home.vue')
const Welcome = () => import('../components/Welcome.vue')
const User = () => import('../components/User/User.vue')
const Roles = () => import('../components/Right/Roles.vue')
const Rights = () => import('../components/Right/Rights.vue')
const Goods = () => import('../components/Goods/Goods.vue')
const Params = () => import('../components/Goods/Params.vue')
const Categories = () => import('../components/Goods/Categories.vue')
const AddGoods = () => import('../components/Goods/AddGoods.vue')
const Order = () => import('../components/Order/Order.vue')
const Report = () => import('../components/Report/Report.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path: '/welcome', component: Welcome },
      { path: '/users', component: User },
      { path: '/roles', component: Roles },
      { path: '/rights', component: Rights },
      { path: '/goods', component: Goods },
      { path: '/params', component: Params },
      { path: '/categories', component: Categories },
      { path: '/goods/add', component: AddGoods },
      { path: '/orders', component: Order },
      { path: '/reports', component: Report },


    ]
  }
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]

const router = new VueRouter({
  routes
})

// 路由守卫beforeEach
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next();
  const tokenstr = window.sessionStorage.getItem('token');
  if (!tokenstr) return next('/login');
  next();
})
export default router
